package com.sskj.b70.common;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.lzy.okgo.OkGo;
import com.sskj.b70.MyAppLication;
import com.sskj.b70.receiver.ScreenBroadcastReceiver;
import com.sskj.b70.utils.LanguageUtil;
import com.sskj.b70.utils.SPUtils;
import com.sskj.b70.v.activity.LockActivity;

/**
 * Created by lvzhihao on 17-5-25.
 */

public class BaseActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
    private long time = -2;
    private int count = 0;
    private ScreenBroadcastReceiver mScreenReceiver;

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        AppManager.getAppManager().addActivity(activity);
        if (!LanguageUtil.isSameWithSetting(activity)) {
            LanguageUtil.changeAppLanguage(activity,
                    LanguageUtil.getAppLocale(activity), true);

        }
        if (!LanguageUtil.isSameWithSetting(App.INSTANCE)){
            LanguageUtil.changeAppLanguage(App.INSTANCE,
                    LanguageUtil.getAppLocale(App.INSTANCE), true);
        }

    }

    @Override
    public void onActivityStarted(Activity activity) {
        if (MyAppLication.IS_HOME) {
            MyAppLication.IS_HOME = false;
            if (MyAppLication.isLogin() && (Boolean) SPUtils.get(Constants.IS_GESTURE_ON, false, MyAppLication.getID())) {
                LockActivity.check(activity);
            }
        }
    }

    @Override
    public void onActivityResumed(Activity activity) {

    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        AppManager.getAppManager().finishActivity(activity);

        OkGo.getInstance().cancelTag(activity);


    }
}
